make install DESTDIR="$PKG"

(
        echo "# Automatically generated by $pkgname-$pkgver-$pkgrel"
        echo "# $(date -u)"
        echo "#"
        cd "$PKG"/usr/share/ca-certificates
        find . -name '*.crt' | sort | cut -b3-
) > "$PKG"/etc/ca-certificates.conf

# generate the bundle in similar way as update-ca-certificates would do
for i in $(ls *.crt | sort); do
        cat "$i"
        printf "\n"
done > "$PKG"/etc/ssl/certs/ca-certificates.crt


cat > "$PKG"/etc/ca-certificates/update.d/certhash <<-EOF
#!/bin/sh
exec /usr/bin/c_rehash /etc/ssl/certs
EOF
chmod +x "$PKG"/etc/ca-certificates/update.d/certhash

mv $PKG/usr/sbin/* $PKG/usr/bin/
rmdir $PKG/usr/sbin
rm -rf $PKG/usr/local
